#include <gtest/gtest.h>
#include "viml/value.h"

using namespace viml;

TEST(ValueTypeTest, NumberVsFloatDistinction) {
    // 测试整数类型
    Value integer = Value::make_number(42);
    EXPECT_EQ(integer.type(), ValueType::NUMBER);
    EXPECT_TRUE(integer.is_number());
    EXPECT_FALSE(integer.is_float());
    EXPECT_EQ(integer.as_number(), 42);
    
    // 测试浮点数类型
    Value floating = Value::make_float(3.14);
    EXPECT_EQ(floating.type(), ValueType::FLOAT);
    EXPECT_FALSE(floating.is_number());
    EXPECT_TRUE(floating.is_float());
    EXPECT_DOUBLE_EQ(floating.as_float(), 3.14);
    
    // 测试整数值的浮点数也应该是FLOAT类型
    Value float_int = Value::make_float(42.0);
    EXPECT_EQ(float_int.type(), ValueType::FLOAT);
    EXPECT_FALSE(float_int.is_number());
    EXPECT_TRUE(float_int.is_float());
    EXPECT_DOUBLE_EQ(float_int.as_float(), 42.0);
}

TEST(ValueTypeTest, NumberFloatConversion) {
    Value integer = Value::make_number(42);
    Value floating = Value::make_float(3.14);
    
    // 测试类型转换
    EXPECT_DOUBLE_EQ(integer.to_float(), 42.0);
    EXPECT_EQ(floating.to_number(), 3);  // 截断小数部分
    
    // 测试字符串转换
    EXPECT_EQ(integer.to_string(), "42");
    EXPECT_EQ(floating.to_string(), "3.140000");
}

TEST(ValueTypeTest, ArithmeticOperations) {
    Value integer1 = Value::make_number(10);
    Value integer2 = Value::make_number(5);
    Value float1 = Value::make_float(3.5);
    Value float2 = Value::make_float(2.0);
    
    // 整数 + 整数 = 整数
    Value int_result = integer1 + integer2;
    EXPECT_EQ(int_result.type(), ValueType::NUMBER);
    EXPECT_EQ(int_result.as_number(), 15);
    
    // 整数 + 浮点数 = 浮点数
    Value mixed_result = integer1 + float1;
    EXPECT_EQ(mixed_result.type(), ValueType::FLOAT);
    EXPECT_DOUBLE_EQ(mixed_result.as_float(), 13.5);
    
    // 浮点数 + 浮点数 = 浮点数
    Value float_result = float1 + float2;
    EXPECT_EQ(float_result.type(), ValueType::FLOAT);
    EXPECT_DOUBLE_EQ(float_result.as_float(), 5.5);
}